package com.neu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.mapper.InventoryMapper;
import com.neu.po.Inventory;
import com.neu.po.InventoryExample;
@Service
public class InventoryServiceImpl implements InventoryService {

	@Autowired
	private InventoryMapper inventoryMapper;
	
	@Override
	public PageInfo<Inventory> getPaged(int pageNum, int pageSize, String keyword) {
		InventoryExample example = new InventoryExample();
		
		PageHelper.startPage(pageNum, pageSize);
		
		List<Inventory> list = inventoryMapper.selectByExample(example);
		
		PageInfo<Inventory> pageinfo = new PageInfo<>(list);
		
		return pageinfo;
	}

	@Override
	public List<Inventory> getAllGoods() {
		InventoryExample example = new InventoryExample();
		return inventoryMapper.selectByExample(example);
	}

	@Override
	public List<Inventory> getByGoodsId(int goodsid) {
		InventoryExample example = new InventoryExample();
		
		example.or().andGoodsEqualTo(goodsid);
		
		return inventoryMapper.selectByExample(example);
	}

	@Override
	public int update(Inventory inventory) {
		
		return inventoryMapper.updateByPrimaryKey(inventory);
	}

}
